package com.sakura.test;

import com.sakura.bean.Person;
import com.sakura.config.MainConfigOfPropertyValue;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * @author Sakura
 * @Date 2023-02-24 13:29
 */
public class IOCTest_PropertyValue {

    private AnnotationConfigApplicationContext configApplicationContext
            = new AnnotationConfigApplicationContext(MainConfigOfPropertyValue.class);

    @Test
    public void testPropertyValue(){
        String[] beanDefinitionNames = configApplicationContext.getBeanDefinitionNames();
        for (String name : beanDefinitionNames){
            System.out.println(name);
        }

        Person personValue = (Person) configApplicationContext.getBean("PersonValue");
        System.out.println("============="+personValue);

        ConfigurableEnvironment environment = configApplicationContext.getEnvironment();
        String property = environment.getProperty("person.nickName");
        System.out.println("property = " + property);

        configApplicationContext.close();
    }
}
